<template>
  <div class="user-container">
    <!-- <van-nav-bar v-if="activeTab != 0" :title="title" :left-text="pathname == '/user'? '': '返回'" :left-arrow="pathname != '/user'" @click-left="onClickBack"/> -->
    <div class="user-content">
      <shoporder v-if="activeTab == 0"></shoporder>
      <shopgoods v-if="activeTab == 1"></shopgoods>
      <shopcenter v-if="activeTab == 2"></shopcenter>
    </div>
    <van-tabbar @change="change" v-model="activeTab" active-color="#ff9c15">
      <van-tabbar-item>
        <span :class="activeTab == 0? 'red' :'grey'">订单管理</span>
        <img
          slot="icon"
          :src="activeTab == 0 ? require('@/assets/img/tab_ddgl_Y.png') : require('@/assets/img/tab_ddgl_N.png')"
        >
      </van-tabbar-item>
      <van-tabbar-item>
        <span :class="activeTab == 1?'red':'grey'">商品管理</span>
        <img
          slot="icon"
          :src="activeTab == 1 ? require('@/assets/img/tab_spgl_Y.png') : require('@/assets/img/tab_spgl_N.png')"
        >
      </van-tabbar-item>
      <van-tabbar-item>
        <span :class="activeTab == 2?'red':'grey'">个人中心</span>
        <img
          slot="icon"
          :src="activeTab == 2 ? require('@/assets/img/tab_grzx_Y.png') : require('@/assets/img/tab_grzx_N.png')"
        >
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
import Shopcenter from "./shopcenter.vue";
import Shopgoods from "./shopgoods.vue";
import Shoporder from "./shoporder.vue";
import { clearInterval } from "timers";
export default {
  components: {
    Shopcenter,
    Shopgoods,
    Shoporder
  },
  data() {
    return {
      pathname: window.location.pathname,
      title: "首页",
      activeTab: 0,
      icon: {
        normal: "@/assets/img/btn_sy_Y.png",
        active: "@/assets/img/btn_sy_Y.png"
      }
    };
  },
  created() {
    this.Suk_addcount();
    localStorage.setItem("logintp",'shop');
  },
  methods: {
    Suk_addcount() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      let Sukdata = {
        userId: localStorage.getItem("userid")
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/user/updateDing", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              console.log(res.data, 11111111111111112);
              that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    },
    change() {
      if (this.activeTab == 0) {
        this.title = "首页";
      } else if (this.activeTab == 1) {
        this.title = "订单";
      }
    },
    onClickBack() {}
  },

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (vm.activeTab == 0 && to.path == "/user") {
        vm.title = "首页";
      } else {
        vm.title = to.meta.title;
      }
      if (!localStorage.getItem("userid")) {
        vm.$router.push({
          name: "login"
        });
      }
      if (
        from.name == "addnewgood" ||
        from.name == "setclass" ||
        from.name == "setshopdetail"
      ) {
        vm.activeTab = 1;
      } else if (
        from.name == "shopcount" ||
        from.name == "usercomment" ||
        from.name == "shopnotice" ||
        from.name == "bind" ||
        from.name == "shopdesc" ||
        from.name == "ridewallet" ||
        from.name == "shopdesc" ||
        from.name == "shoplist"
      ) {
        vm.activeTab = 2;
      }
    });
  }
};
</script>
<style scoped>
.user-content {
  width: 100%;
  font-size: 0.3rem;
}
.user-container {
  width: 100%;
}
.grey {
  color: #8a8a8a;
}
.red {
  color: #ff9c15;
}
</style>
